package com.jsong.linuo.array;

/**
 * @Author:
 * @CreateTime: 2025-04-22
 * @Description: 可变参数练习:拼接字符串
 */

public class Array03 {
    public static void main(String[] args) {
        String result1 = contact1("你好", "你们好", "大家好");
        System.out.println("result = " + result1);

        String result2 = contact2("-", "哈哈哈", "呵呵呵", "嘿嘿嘿");
        System.out.println("result2 = " + result2);
    }

    /**
     * @param s 需要拼接的字符串
     * @return 返回拼接之后的字符串
     */
    public static String contact1(String... s) {
        String str = "";
        for (int i = 0; i < s.length; i++) {
            str += s[i];
        }

        return str;
    }

    /**
     * @param regex 分隔符号
     * @param s     需要拼接的字符串
     * @return 返回拼接完成的字符串
     */
    public static String contact2(String regex, String... s) {
        String str = "";
        for (int i = 0; i < s.length; i++) {
            if (i == s.length - 1) {
                str += s[i];
            } else {
                str += s[i] + regex;
            }

        }

        return str;
    }
}
